/**
 * @Author：ming
 * @Date：2023/10/1 2:41 PM
 * @Filename：Lc141
 */

/**
 * @author ming
 */
public class Lc141 {
    public boolean hasCycle(ListNode head) {

        boolean flag = false;
        ListNode fast = head;
        ListNode slow = head;

        while (fast!=null&&slow!=null){
            slow = getNext(slow);
            fast = getNext(fast);
            fast = getNext(fast);
            if(fast==slow&&fast!=null){
                flag = true;
                break;
            }
        }


        return flag;
    }


    public ListNode getNext(ListNode p){
        if(p==null){
            return p;
        }else {
            return p.next;
        }
    }




}
